<?
	class c_mvc_user_controller extends c_base_controller
	{
		var $user = 0;
	
		function index($args)
		{
			if (!$this->user)
			{
				$this->user = new c_mvc_user_model($args[2]);
			}
			
			$this->usernames = glob($this->data_path.'users/*');
			foreach($this->usernames as $k => $username)
				$this->usernames[$k] = basename($username);
				
			return $this->show('index');
		}
		
		function load($args)
		{
			global $mvc;
			$name = isset($_REQUEST['name']) ? $_REQUEST['name'] : ''; // !Безопасность имя пользователя = путь.
			$args[2] = $name;
			return $this->index($args);
		}
		
		function save($args)
		{
			global $mvc;
			$name = isset($_REQUEST['name']) ? $_REQUEST['name'] : ''; // !Безопасность имя пользователя = путь.
			if ($name)
			{
				$this->user = new c_mvc_user_model($name);
				$this->user->name = $_REQUEST['name'];
				$pass = (isset($_REQUEST['password']) && $_REQUEST['password']) ? md5($_REQUEST['password']) : '';				
				$this->user->password = $pass;
				$this->user->config['inherits'] = $_REQUEST['inherits'];
				$this->user->permissions = explode("\n", str_replace("\r\n", "\n", $_REQUEST['permissions']));
				$this->user->save();
			}
			
			$args[2] = $name;
			return $this->index($args);
		}
		
		function kill($args)
		{
			global $mvc;
			$name = isset($_REQUEST['name']) ? $_REQUEST['name'] : ''; // !Безопасность имя пользователя = путь.
			$this->user = new c_mvc_user_model($name);
			$this->user->kill();
			return $this->index($args);		
		}
		
		function hallo($args)
		{
			return 'this is hallo wethod of the mvc_user';
		}
	}
?>